package com.dwxt.parabolic.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.common.base.StatusCode;
import com.dwxt.common.util.SmsUtil;
import com.dwxt.common.util.ValidCodeUtils;
import com.dwxt.parabolic.utils.RedisUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/parabolic/sms")
public class SmsController {

    @RequestMapping("/send")
    public BaseResult send(String phone) throws UnsupportedEncodingException {
        String captcha = ValidCodeUtils.generateNumber(4);
        String postData = "您的验证码是：【" + captcha + "】。请不要把验证码泄露给其他人。如非本人操作，可不用理会！";
        postData =
                "account=ZTCQ888&password=ZTCQ888&mobile=" + phone + "&content=" + java.net.URLEncoder.encode(postData, "utf-8");
        //验证码5分钟有效
        RedisUtil.set(phone, captcha, (long) 5 * 60);
        return SmsUtil.SMS(postData);
    }
}
